/*
 * DecideGameStartView.cpp
 *
 *  Created on: 08/06/2014
 *      Author: javier
 */

#include "DecideGameStartView.h"
#include "BZPView.h"

#define TEXTURE_W 590.0f
#define TEXTURE_H 590.0f

DecideGameStartView::DecideGameStartView(BZPView* view, SDLWindow* window) {
	this->view = view;
	this->window = window;
	std::string resDir = properties.getProperty("res_dir");
	std::string textureName = resDir + "decide.jpg";
	texture = window->loadTexture(textureName);
	geometry.x = 0;
	geometry.y = 0;
	geometry.w = properties.getPropertyAsInt("screen.width");
	geometry.h = properties.getPropertyAsInt("screen.height");

}

DecideGameStartView::~DecideGameStartView() {
	// TODO Auto-generated destructor stub
}

void DecideGameStartView::handleClick(int x, int y) {
	int width = properties.getPropertyAsInt("screen.width");
	double widthFactor = width / TEXTURE_W;
	int height = properties.getPropertyAsInt("screen.height");
	double heightFactor = height / TEXTURE_H;
	if (y > 450 * heightFactor && y < 498 * heightFactor) {
		if (x > 81 * widthFactor && x < 172 * widthFactor) {
			// si
			view->sendStartMatch(true, idPartida);
		} else if (x > 405 * widthFactor && x < 507 * widthFactor) {
			// no
			view->sendStartMatch(false, idPartida);
		}
	}
}

void DecideGameStartView::render() {
	window->renderTexture(texture, &geometry);
}

void DecideGameStartView::setIdPartida(const std::string& idPartida) {
	this->idPartida = idPartida;
}
